package io.aircraft.modules.log.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.aircraft.common.page.PageData;
import io.aircraft.common.service.impl.CrudServiceImpl;
import io.aircraft.modules.log.dao.SysLogWorkDao;
import io.aircraft.modules.log.dto.SysLogWorkDTO;
import io.aircraft.modules.log.entity.SysLogWorkEntity;
import io.aircraft.modules.log.service.SysLogWorkService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 作业日志
 *
 * @author Cycle gengruyi01@163.com
 * @since 1.0.0 2022-11-21
 */
@Service
public class SysLogWorkServiceImpl extends CrudServiceImpl<SysLogWorkDao, SysLogWorkEntity, SysLogWorkDTO> implements SysLogWorkService {

    @Override
    public PageData<SysLogWorkDTO> page(Map<String, Object> params) {
        IPage<SysLogWorkEntity> page = baseDao.selectPage(
                getPage(params, "id", false),
                getWrapper(params));
        return getPageData(page, SysLogWorkDTO.class);
    }

    @Override
    public QueryWrapper<SysLogWorkEntity> getWrapper(Map<String, Object> params) {
        String id = (String) params.get("id");
        String workName = (String) params.get("workName");
        String relateNo = (String) params.get("relateNo");
        String startDate = (String) params.get("startDate");
        String endDate = (String) params.get("endDate");

        QueryWrapper<SysLogWorkEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);
        wrapper.eq(StringUtils.isNotBlank(relateNo), "relate_no", relateNo);
        wrapper.like(StringUtils.isNotBlank(workName), "work_name", workName);
        wrapper.ge(StringUtils.isNotBlank(startDate), "create_date", startDate);
        wrapper.le(StringUtils.isNotBlank(endDate), "create_date", endDate);

        return wrapper;
    }


}